package com.cyt.base.redis;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cache.annotation.CachingConfigurationSelector;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * @author taocongcong
 * @create 2017-07-07 14:27
 */
@Configuration
public class JedisCache extends CachingConfigurationSelector {

    private static final Logger logger = LoggerFactory.getLogger(JedisCache.class);

    private static final String host = "47.114.130.29";

    private static final int port = 6379;

    private static final int maxTotal = 60000;

    private static final int maxIdle = 300;

    private static final boolean testOnBorrow = true;

    @Bean(name="jedisPool")
    public JedisPool jedisPool() {
        logger.info("JedisPool注入成功！！");
        logger.info("redis地址：" + host + ":" + port);
        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
        jedisPoolConfig.setMaxIdle(maxIdle);
        jedisPoolConfig.setMaxTotal(maxTotal);
        jedisPoolConfig.setTestOnBorrow(testOnBorrow);
        JedisPool jedisPool = new JedisPool(jedisPoolConfig, host , port);
        return jedisPool;
    }
}
